#+TITLE: Gnus Configuration
#+AUTHOR:Joshua Branson
#+LATEX_HEADER: \usepackage{lmodern}
#+LATEX_HEADER: \usepackage[QX]{fontenc}

* Gnus Quick Start
:PROPERTIES:
:ID:       3cbb9013-b4c2-4e59-902a-2100e3d4bee0
:END:

Many free software projects use mailing lists as the primary means of
communication and development.  Just being subscribed to two or three
mailing lists can be overwhelming.  Some mailing lists can have
hundreds of emails sent per day!  That's where Gnus starts to shine.
Gnus will help you keep track and respond to all of the hundreds of
email messages.

Gnus was originally designed to be a newsreader, which is /not/ an
email client.  If you are reading a LOT of mailing lists, or have a
ridiculous amount of mail to get through, then you may like Gnus.  If
you are not subscribed to many mailing lists, then you should probably
not use Gnus.

This quick start guide will help you set up gnus to manage an email
account from dismail.de, which is a gratis and libre email
provider. If you decide to use a dismail.de account, then please
consider donating.  Another good email provider is riseup.net.  Both
email providers use only free software, which means they both are
significantly better than gmail, yahoo, or hotmail.  If you prefer a
commercial solution, you might like fastmail, which is a company that
is developing new email standards.

This guide describes how to set up email in a way that will "just
work."



"difficult-to-set-up" options are briefly mentioned in the section
[[id:2a55790d-26a5-476d-8d7f-b43814d95893][Isn't IMAP slow and old school?]]

Some cool guides online:

https://github.com/gongzhitaao/GnusSolution/blob/master/gnus-conf.el

https://fontawesome.com/v3.2/cheatsheet/

** Telling Gnus who you are
:PROPERTIES:
:ID:       36b58510-9bd1-4842-9fea-00503697d398
:END:

#+BEGIN_SRC emacs-lisp :tangle no
(setq
 user-mail-address	"steven@dismail.de"
 user-full-name	"Steven Crowder")
#+END_SRC

You will also want to set up the connection.

#+BEGIN_SRC emacs-lisp
  (setq gnus-select-method
        '(nnimap "imap.dismail.de"))
#+END_SRC


*** If you need to use multiple email accounts

"gnus-select-methods" is the default email account that you have, and "gnus-secondary-select-methods" is for any other email account that you have (or news accounts, RSS feeds, maildirs, etc).  This is useful if you have a dismail.de account and a riseup.net account, and other email accounts.

#+BEGIN_SRC emacs-lisp :tangle no
  (setq gnus-secondary-select-methods
        '((nnimap "imap.dismail.de"
                  (nnimap-stream ssl)))
        (nnimap "uni"
                   ("imap.duke.edu")))
#+END_SRC

*** If your remote server has non standard options

You really should not need to specify this information, but if after reading [[id:3cbb9013-b4c2-4e59-902a-2100e3d4bee0][Gnus Quick Start]], and M-x gnus still doesn't work, then you try be more explicit in your connection methods.

#+BEGIN_SRC emacs-lisp :tangle no
  (setq gnus-select-method
        '(nnimap "my imap method"
                 (nnimap-address "imap.some-weird-address.edu")
                 (nnimap-server-port "234")  ;;maybe it uses an odd port
                 (nnimap-stream ssl)))
#+END_SRC

** Isn't IMAP slow and old school?
:PROPERTIES:
:ID:       2a55790d-26a5-476d-8d7f-b43814d95893
:END:

Not really.  Most online email clients still use IMAP.  It works for them.  IMAP is the recommended way to read your email, because it just works.  If you want it to just work, then skip this chapter.

However, if you are or want to be a power user, there are other ways of using Gnus that offer better searching capabilities.  The two modern methods that come to mind are maildir, or a maildir combined with a local dovecot server.  The latter is what the current maintainer of Emacs does.

*** COMMENT local imap connection with dovecot (what the current maintainer of emacs does)
*** COMMENT So you'd rather use a maildir?
Well first you need to set up a way to download your email.  I recommend [[https://wiki.archlinux.org/index.php/Isync][isync]].  It seems to be getting a lot of hype.  It syncs email back and forth between you and your maildir.

Here's some info from the Emacs list.
https://lists.gnu.org/archive/html/info-gnus-english/2016-09/msg00051.html
https://lists.gnu.org/archive/html/info-gnus-english/2016-09/msg00051.html

Here's an initial info from the internet archive:
http://web.archive.org/web/20160305042051/http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html

Once you have your downloaded mail, then you need to tell Gnus about the maildir.
** Starting Gnus for the first time
:PROPERTIES:
:ID:       7993a3f7-0338-4a44-ab58-c7da847172f0
:END:

=M-x Gnus=

After Gnus loads you should see a mostly empty screen. This is your group buffer.  It displays all of your groups, which a normal email client would call folders. Gnus doesn't show you all of your email folders, because you need to tell Gnus which folders to use by default.  [fn:3]  To do this, press the =^= key.

You are now in the server buffer.  The server buffer shows you all of your live accounts (aka email connections) and how you interact with each server.  If you use gnus with 5 different email accounts, then you will see 5 different servers.  Press RET on the email server that says "dismail.de".

Now you should see your email folders or /groups/.  To subscribe to a /group/ press "u".  You should probably subscribe to your Inbox, Sent, Trash, and Draft folders.  When you are done subscribing to /groups/ (folders), press =q=.

Now you should see all of your email folders.  This buffer is called the group buffer.  Navigate to your inbox, and press RET.  You are now in the summary buffer.  You can move to the next unread email with the "n" key.  When you do that, you should see your email open up in the article buffer.  You can scroll through your email with the "SPC" key.  You can read the next email by pressing "SPC" multiple times or by hitting "n".

Before we leave your inbox, here is a list of useful commands for the summary buffer:

- n
  Go to the next unread message
- p
  Go to the previous unread message
- N
  Go the next read message
- P
  Go to the previous unread message
- q
  quit (exit) this group buffer
- ^
  go to the previous parent message
- A T
  show the current article's full thread
- c g
  mark all email in this group as read

Now press "q" to exit your inbox.   You will now see the rest of your email folders.  If you want to mark all of the email in your trash folder as read, go ahead and place point over it, and press "c g" to mark all the emails as read.

Press "g" to make gnus check for new mail.  You should see your Inbox and Trash folder disappear.  That's because Gnus, by default only shows folders that contain unread emails.  Once you get used to this, it's really nice.

If for some reason you want to display all of your email folders, press "g".  If you want to go to a particular email folder, then press "j".  If you want to search for a particular email, place point over the email folder you'd like to search and press "GG RET <your search string here> RET".

** Some more information

read these pages:
https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org
http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-glimpse-of-bbdb.html
http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-using-gnus-to.html
practical gnus tutorial
http://blog.binchen.org/posts/notes-on-using-gnus.html#sec-1
http://sachachua.com/blog/2008/05/emacs-gnus-searching-mail/
using mime in gnus http://orgmode.org/worg/org-contrib/org-mime.html
When you first start gnus you need to type "t".  Not sure why, but you do.
You also need to type j (jump) to a particular folder
also sometimes your inboxes won't sure up (if they are contain no unread mail mail) so
to see all inbex

(setq smtpmail-smtp-service 587
      gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
Put the following in your ~/.authinfo file, replacing <USER> with your email address and replacing <PASSWORD> with your password—or your application-specific password:

When sending your first email from gnus, you might get a STARTTLS error. If you’re using homebrew in Mac OS X, you can install the necessary package with brew install gnutls.

You can find more information in the following sections.

* Setting up Gnus
  :PROPERTIES:
  :ID:       6e745af2-398f-49a2-a695-59e0c979bd9e
  :END:

   This files just sets up some variables that I use later on, that I want to be secret.
   #+BEGIN_SRC emacs-lisp
     (require 'gnus)
     (let ((path "~/.config/emacs/lisp/init-gnus-secret.org"))
       (when
           (and
            (file-exists-p path)
            (file-readable-p path))
         (org-babel-load-file path)))
  #+END_SRC

** pretty obvious settings
:PROPERTIES:
:ID:       6fa17430-dc31-4337-8860-462d4f324993
:END:

Gnus will always ask you if you want to read the dribble file.  I
don't want Gnus to ask me for permission every time to read a startup
file.  Just read it.
#+BEGIN_SRC emacs-lisp
  (setq gnus-always-read-dribble-file t)
#+END_SRC

** Posting Styles
:PROPERTIES:
:ID:       0bf948b7-d13d-4aff-b6ff-b094971aad15
:END:
[[info:gnus#Posting%20Styles][info:gnus#Posting Styles]]

Changing my signature based on what email account I'm using.

Posting an article is the same thing as sending an email, since gnus
is a usenet reader, gnus uses usenet terminology.

I can specify posting styles depending on the account.  So for example
I can specify that when I reply to an article (email), I should use a
specific From field.  That's what this next bit of code does.

 #+BEGIN_SRC emacs-lisp
     (setq my/default-signature
           (concat user-full-name " (joshuaBPMan in #guix)"
                   "\nSent from Emacs and Gnus
     https://gnucode.me
     https://video.hardlimit.com/accounts/joshua_branson/video-channels
     https://propernaming.org
     \"You can have whatever you want, as long as you help
   enough other people get what they want.\" - Zig Ziglar
     "))

     (setq gnus-posting-styles
           '(
             ;; My default hotmail posting style
             (".*"
              (signature my/default-signature)
              (address user-mail-address))
             ;; when I post to something else stuff
             (".*Some-string-that-matches-a-different-email-account.*"
              (signature "Some Cool Signature\nThis is on a new line")
              (address "someEmailAccount@riseup.net"))
             ))

   #+END_SRC

 But what about C-x m ?  Well you need to tell it what your signature is as well.
#+BEGIN_SRC emacs-lisp
   (setq message-signature my/default-signature)
#+END_SRC

BUT basically, if I have a bunch of email accounts, It would be nice that when I reply or post new articles (email), than Gnus will change the From automatically.  This method will definitely work for posting articles, but will to work when replying to articles?


   #+BEGIN_SRC emacs-lisp :tangle no
   (setq gnus-posting-styles
           '(
             ;; My default hotmail posting style
             (".*"
              (signature "Joshua\nSent From Emacs")
              (address "joeRoegan@hotmail.com"))
             ;; when I post to purdue stuff
             (".*dismail.*"
              (signature "Joshua Branson\nPurdue Univeristy\nHonors College\nSent From Emacs")
              (address "someDismailAccount@dismail.de"))
             ))

   #+END_SRC

** COMMENT polymode
   :PROPERTIES:
   :ID:       018c1252-b2f1-412f-80da-27d7f170720b
   :END:

   #+BEGIN_SRC emacs-lisp
     (require 'polymode)

     (defun my-set-up-polymode ()
       (define-hostmode poly-message-hostmode
         :mode 'message-mode)

       (define-innermode poly-message-org-innermode
         :mode 'org-mode
         :head-matcher "--text follows this line--\n"
         :tail-matcher "^--\n"
         :head-mode 'host
         :tail-mode 'host)

       (define-polymode poly-message-mode
         :hostmode 'poly-message-hostmode
         :innermodes '(poly-message-org-innermode)))

     ;; (add-to-list 'auto-mode-alist
     ;;              '("\(?:\*\(?:mail\*\|unsent mail\*org\)\)" . poly-message-mode))

     (add-to-list 'auto-mode-alist '("^\\*mail\\*$" . poly-message-mode))
   #+END_SRC

** Making Gnus prettier
   :PROPERTIES:
   :ID:       cda56b7e-e071-4dd1-9619-fe7a317d70c0
   :END:
   My default summary line format
   #+BEGIN_SRC emacs-lisp
     (setq  gnus-summary-line-format "%d %U%R%z%I%(%[%4L: %-23,23f%]%) %s \n")
   #+END_SRC

   more attractive summary buffer
   http://groups.google.com/group/gnu.emacs.gnus/browse_thread/thread/a673a74356e7141f
   #+BEGIN_SRC emacs-lisp
   (when window-system
       (setq gnus-sum-thread-tree-indent "  ")
       (setq gnus-sum-thread-tree-root "● ")
       (setq gnus-sum-thread-tree-false-root "◯ ")
       (setq gnus-sum-thread-tree-single-indent "◎ ")
       (setq gnus-sum-thread-tree-vertical        "│")
       (setq gnus-sum-thread-tree-leaf-with-other "├─► ")
       (setq gnus-sum-thread-tree-single-leaf     "╰─► "))

       (setq gnus-summary-line-format
           (concat
            "%0{%U%R%z%}"
            "%3{│%}" "%1{%d%}" "%3{│%}" ;; date
            "  "
            "%4{%-20,20f%}"               ;; name
            "  "
            "%3{│%}"
            " "
            "%1{%B%}"
            "%s\n"))

     (setq gnus-summary-display-arrow t)
   #+END_SRC

** use some org features inside message mode
   :PROPERTIES:
:ID:       9dd9004a-b53e-42a0-b52f-53abfaaafed4
:END:

   This is kind of cool!

   https://orgmode.org/worg/org-tutorials/org-outside-org.html

   #+BEGIN_SRC emacs-lisp
   ;;(add-hook 'message-mode-hook 'orgstruct-mode)
   #+END_SRC
** archiving mail aka coping mail to the sent folder
   :PROPERTIES:
   :ID:       b2a95930-a80c-4a9a-8aed-4b41684841b4
   :END:

   When gnus sends email, it'll copy the sent mail in a local file on
   disk, but sometimes you'd like a copy of that email on the server.
   So after you send an email, gnus will make sure the sent email ends
   up in your "sent" folder.

   #+BEGIN_SRC emacs-lisp :tangle no
     ;; Archive outgoing email in Sent folder on imap.dismail.de
     (setq gnus-message-archive-method '(nnimap "imap.dismail.de")
           gnus-message-archive-group "Sent")

   #+END_SRC
** Make gnus startup faster
   :PROPERTIES:
   :ID:       65e0d067-88fe-4eb0-bfce-5d21c72411f7
   :END:
   These two variables make gnus not check for any new newsgroups and
   stops gnus from trying to filter out outdated newsgroups.  After
   you've opened up gnus a couple of times, you don't need gnus to do
   these things.  But you can always subscribe to new groups by
   pressing "U" in the group buffer.

   #+BEGIN_SRC emacs-lisp
     (setq gnus-check-new-newsgroups nil
           gnus-check-bogus-newsgroups nil)
   #+END_SRC
*** Don't change gnu-read-active-file
 Setting the next line to nil will slow down gnus apparently [[info:gnus#The%20Active%20File][info:gnus#The Active File]]
 So don't do this in your gnus set up.


(setq gnus-read-active-file nil)

*** Fixing the Summary Buffer
    :PROPERTIES:
    :ID:       6c98f225-5cbc-424b-a32f-69e899d41327
    :END:

    There's no need to recenter the summary buffer all the time.  It only slows gnus down.

    #+BEGIN_SRC emacs-lisp
      (setq gnus-auto-center-summary nil)
    #+END_SRC

    Let's enter the summary buffer faster eh?

    #+BEGIN_SRC emacs-lisp
      (setq gnus-nov-is-evil nil
            gnus-show-threads t
            gnus-use-cross-reference nil)
    #+END_SRC
** encrypted email
   :PROPERTIES:
   :ID:       e651daa3-d45f-4e76-8338-0c55f3845108
   :END:
   Until I get newer gpg keys, I'll go ahead and not encrypt stuff

   Let's go ahead and sign and encrypt messages if I recognize the senders by default
   #+BEGIN_SRC emacs-lisp
     (setq
      mm-verify-option 'known
      mm-decrypt-option 'known)
   #+END_SRC

   #+begin_src emacs-lisp
     (setq
      mm-verify-option 'never
      mm-decrypt-option 'never)
   #+end_src

*** On reply encrypt my email
:PROPERTIES:
:ID:       d070613f-2fd6-4273-8430-855f3f182d7e
:END:
    Let's reply and encrypt/sign messages if you know the user by default and if that message is encrypted
    https://www.gnu.org/software/emacs/manual/html_node/gnus/Security.html#Security
    #+BEGIN_SRC emacs-lisp
      (setq
       gnus-message-replysign nil
       gnus-message-replyencrypt nil)
    #+END_SRC

*** managing spam
Gnus comes with some cool spamming features, but it's not good.  Why use it, when the email server can do this?

  #+BEGIN_SRC emacs-lisp :tangle no
     (setq spam-blacklist "/home/joshua/.config/emacs/lisp/blacklist"
           spam-use-blacklist t)
     (spam-initialize)
   #+END_SRC
** Searching in Gnus
   :PROPERTIES:
   :ID:       63ae4bc7-3e9b-4add-a364-db36ec2975e5
   :END:
   Set up search in GNUS.  If you are using IMAP, then this package will
   just work for you.

   http://www.emacswiki.org/emacs/GnusGmail#toc21

   #+BEGIN_SRC emacs-lisp  :tangle no
   ;;(use-package nnir :defer t)
   #+END_SRC

** setting up email lists
   :PROPERTIES:
   :ID:       c1e24635-82c3-4fe1-9c7a-439175e15ca7
   :END:

   Sometimes when you are subscribed to mailing lists, you can get
   multiple email messages.  Suppose that you email the mailing list.
   Someone can respond to you directly and CC the mailing list.  To
   avoid that, tell Gnus which mailing lists you are subscribed to.
   This way, someone will only respond to the mailing list.  Gnus does
   this by using the Mail-Followup-To header.

[[info:message#Mailing%20Lists][   info:message#Mailing Lists]]

   #+BEGIN_SRC emacs-lisp
     (setq message-subscribed-addresses
           '(
             "bug-guix@gnu.org"
             "bug-hurd@gnu.org"
             "guix-devel@gnu.org"
             "help-guix@gnu.org"
             "emacs-devel@gnu.org"
             "arm-netbook@lists.phcomp.co.uk"
             ))

     ;; this bit of code below tells gnus to look for group parameters that
     ;; tell gnus, this group is an email list.  These two options below
     ;; though, should really only be needed on "closed mailing lists" aka
     ;; lists where people are expected to be subscribed to get the email.

     ;; (setq message-subscribed-address-functions
     ;;       '(gnus-find-subscribed-addresses))

     ;; (setq gnus-parameters '(
     ;;                         (to-address . "guix-devel@gnu.org")
     ;;                         (subscribed . t)
     ;;                         ))

   #+END_SRC

** Kill mail buffer after you send an email
   :PROPERTIES:
   :ID:       d7cbe98a-4be8-4ffb-87d8-ce8d62302ae2
   :END:

   Message mode is rather silly in that it does not kill the send
   message buffer after you send an email.  It's silly to still see
   the sent buffer after you've sent it, so this fixes that.  After
   you send a message, the sent buffer disappears.

   #+BEGIN_SRC emacs-lisp
     (setq message-kill-buffer-on-exit t)
   #+END_SRC
** scanning news with gnus daemon
   :PROPERTIES:
   :ID:       50a08919-f279-419e-abe6-9c179130a872
   :END:
   [[info:gnus#Daemons][info:gnus#Daemons]]

   Gnus Demon lets you do various tasks at certain points in time.
   For example, suppose you want Gnus to check for new email.  You can
   do that fairly easily with a ready made handler called
   gnus-demon-scanmail.  The following will check for news email after
   Emacs has been idle for two minutes, but it may only show updates
   in Emacs.  To get an awesome popup, I'll have to do more fiddling.
   Filezilla is able to show me updates when it's done uploading
   files.  At least it has in the past.  BUT in order to show updates,
   I need to have dbus.  GuixSD may not have dbus.

   #+BEGIN_SRC emacs-lisp
     (gnus-demon-add-handler 'gnus-demon-add-scanmail nil 2)
   #+END_SRC

   These links below will help me to figure this out.

   http://www.thregr.org/~wavexx/software/gnus-desktop-notify.el/

   https://github.com/jwiegley/alert

   https://www.gnu.org/software/emacs/manual/html_node/elisp/Desktop-Notifications.html
** Making gnus check if I want to add an attachment

   https://www.topbug.net/blog/2016/12/09/attachment-reminder-in-emacs-message-mode/

   (defun my-message-current-line-cited-p ()
     "Indicate whether the line at point is a cited line."
     (save-match-data
       (string-match (concat "^" message-cite-prefix-regexp)
                     (buffer-substring (line-beginning-position) (line-end-position)))))

   (defun my-message-says-attachment-p ()
     "Return t if the message suggests there can be an attachment."
     (save-excursion
       (goto-char (point-min))
       (save-match-data
         (let (search-result)
           (while
               (and (setq search-result (re-search-forward "\\(attach\\|pdf\\|file\\)" nil t))
                    (my-message-current-line-cited-p)))
           search-result))))

   (defun my-message-has-attachment-p ()
     "Return t if the message has an attachment."
     (save-excursion
       (goto-char (point-min))
       (save-match-data
         (re-search-forward "<#part" nil t))))

   (defun my-message-pre-send-check-attachment ()
     (when (and (my-message-says-attachment-p)
                (not (my-message-has-attachment-p)))
       (unless
           (y-or-n-p "The message suggests that you may want to attach something, but no attachment is found. Send anyway?")
         (error "It seems that an attachment is needed, but none was found. Aborting sending."))))
   (add-hook 'message-send-hook 'my-message-pre-send-check-attachment)

** Summary Buffer

[[info:gnus#Summary%20Sorting][   info:gnus#Summary Sorting]]

   Sorting the summary buffer by most recent date:

   C-u C-c C-s C-d

   I would like this set up for my inbox email account.

** ranking groups
   :PROPERTIES:
   :ID:       5e527dc8-9d1a-427c-a529-fd88fe080194
   :END:

   Make Gnus sort the group buffer based on how often I read each group.
   When you exit the summary buffer, increase the score of that group.
   This makes that group a little bit more important.

   #+BEGIN_SRC emacs-lisp
     (add-hook 'gnus-summary-exit-hook 'gnus-summary-bubble-group)
   #+END_SRC

** displaying your topics when you enter gnus
   :PROPERTIES:
   :ID:       8264d472-e08d-4b10-95bc-0fee75c37a76
   :END:

   Gnus can put various email in certain topic headings.  For instance if
   you have a lot of email from different email servers, you can organize
   them according to topic "Fastmail" and topic "Roundcube".

   #+BEGIN_SRC emacs-lisp
     (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
   #+END_SRC

** read html mail
   :PROPERTIES:
   :ID:       4150a9e8-5bcf-474c-ade4-cec758e7f427
   :END:

   You have 2 main options here.  You can use the elisp shr for this
   or you can use gnus-w3m if you have w3m installed.  Shr is written
   in elisp.  w3m is written in C or C++.  So I'm guessing that w3m is
   faster.  So I'm going to use gnus-w3m.

   I'm assuming that w3m is faster than the built in shr which is used by
   eww.

   I can also use w3m, which uses the emacs-w3m, but I'm not sure how
   updated that is.

   I've decided that I like the default 'shr.  the w3m is really annoying
   to try to use.

   and 3wm has not seen much updates in the past couple of years.
   #+BEGIN_SRC emacs-lisp
     ;;(use-package w3m )
     ;;(setq mm-text-html-renderer 'w3m)
     (setq mm-text-html-renderer 'shr)

     ;; set the max width of the shr-renderer to be 80, which is what
     ;; fill-column is set to.
     (setq shr-width fill-column)

   #+END_SRC

** Expiring Mail

   Mail/email marked as expire-able means that gnus will delete the email
   after a period of time.  I like gnus to delete the email after 30
   days, but it might be better if the email server did this too...idk.

   When you press "E" on a mail item in the summary buffer, this marks
   it as expire-able.

*** Delete mail marked expire-able after 30 days.
   :PROPERTIES:
   :ID:       60caba9f-04ef-470c-9da9-40108bfd53b7
   :END:

   All email that I mark with an E will be deleted in 30 days.

   #+BEGIN_SRC emacs-lisp
   (setq nnmail-expiry-wait 30)
   #+END_SRC

*** Auto expire v. total expire

    It's pretty tedious to have to press E on every article that I
    read.  The Gnus manual recommends to use auto-expire.

    Auto-expire is probably faster and gives you greater flexibility.

    Total-expire does not work well with adaptive scoring.

    I'm going to try to use auto-expire and make gnus press E for me
    everytime I select an article.

    Though I'm not sure how to turn on auto-expiry. I think you
    specify it via group parameters.

    https://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
** deleting boring headers from email
   :PROPERTIES:
   :ID:       48255cfb-8300-4800-8c14-16c5a3525ac4
   :END:
   [[info:gnus#Hiding%20Headers][info:gnus#Hiding Headers]]
   #+BEGIN_SRC emacs-lisp
     (setq gnus-treat-hide-boring-headers 'head)
   #+END_SRC
** automatically configuring how my mail looks
   :PROPERTIES:
   :ID:       c4c986ea-5d81-49c0-9a1c-0d4049337525
   :END:

   The following variables can have the following values:
   - nil   (don't do this treatment)
   - t     (do this treatment on all parts of the message)
   - head  (do this treatment on the headers of the message)
   - first (do this treatment on the first body part)
   - last  (do this on the last body part)

     #+BEGIN_SRC emacs-lisp
     (setq gnus-treat-strip-multiple-blank-lines t)
     (setq gnus-treat-trailing-blank-lines t)
     ;; let's see some smiles in gnus
     (setq gnus-treat-display-smileys t)
     (setq gnus-treat-emphasize 'head)
     #+END_SRC
** gravitars
   :PROPERTIES:
   :ID:       71a27219-d9cc-404f-b9f1-eaaaf56e09ff
   :END:

   This is supposed to show gravitars in my emails.  I'm not sure how well it is working.

   #+BEGIN_SRC emacs-lisp
   (setq gnus-treat-from-gravatar 'head)
   #+END_SRC
** make firefox use gnus when you click on an email online

   Create a file called Emacs mail.

   #+BEGIN_SRC sh :exports code :tangle no
   touch emacsmail
   #+END_SRC

   #+BEGIN_SRC sh :results output :exports both :dir ~/programming/bash/
   cat emacsmail
   #+END_SRC

   #+RESULTS:
   : #!/bin/bash
   : emacsclient -c --eval "(browse-url-mail \"$@\")"

   Then in Firefox's preferences you can specify what program to call when you click on an html email.

** make Gnus open a new frame and call itself Gnus
   :PROPERTIES:
   :ID:       aeaedb21-4ec7-4618-bb66-a16a6e11a683
   :END:

   There some information about this here:   https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html#Creating-Frames
   https://www.gnu.org/software/emacs/manual/html_node/elisp/Frame-Titles.html#Frame-Titles

   Essentially, I'll need to call make-frame, specify that the new frame should have the WM_NAME Gnus.  This means my window manager will think that it is a different program and is not Emacs.

   I'll probably give it a different logo.  And I might change the default theme.  Then I'll add an awesome rule that makes it start in the second tag on startup.  Very cool.

   Currently I can't get gnus to use fastmail, so I'll pass on this.

   #+BEGIN_SRC emacs-lisp
     (defun my/make-gnus-frame ()
       "Make a gnus frame, and make the title Gnus and show the gnus bitmap image."
       (interactive)
       (when window-system
         (with-selected-frame
             (make-frame '(
                           (name . "Gnus")
                           (title . "Gnus")
                           (icon-type . 'default-emacs-icon)
                           ))
           (gnus))))

     ;; (add-hook 'after-init-hook 'make-gnus-frame)

      ;;(select-frame-by-name "Gnus")
   #+END_SRC

   A bitmap image is stored in .bmp.  The .xmp image is for X.

** using gnus automatic scoring stuff
   :PROPERTIES:
   :ID:       3992d090-c903-4fb3-a078-a3d2dc2203b3
   :END:

   Make gnus rank which articles are important to you.
   #+BEGIN_SRC emacs-lisp
     (setq gnus-use-adaptive-scoring t)
   #+END_SRC

** I've been getting a weird error, hopefully this'll fix it
   :PROPERTIES:
   :ID:       2832eeb8-7df9-415f-a802-5f80d0a559f3
   :END:

   #+BEGIN_SRC emacs-lisp
     (setq mail-user-agent  'sendmail-user-agent)
   #+END_SRC
** Provide init-gnus
   :PROPERTIES:
   :ID:       2d4021b8-caa2-43fd-9652-e9df2340f70e
   :END:
   #+BEGIN_SRC emacs-lisp
     (provide 'init-gnus)
   #+END_SRC
** COMMENT some things I don't use at the moment
*** splitting up my inboxes
   Don't use gnus to split your incoming email.  Gnus is slow at doing
   that and it's much easier to let the server to do the mail splitting.

   I used to have this say nnmail-split methods, but I'm not using the
   nnmail backend!  I'm using nnimap.  Maybe this will actually let gnus
   properly split my mail into proper topics.

   #+BEGIN_SRC emacs-lisp :tangle no
     ;;(setq nnimap-split-method-default)
     (setq nnmail-split-methods
           '(
           ("Accrisoft Support" "^From:.*support@accrisoft.com.*$")
             ("Basecamp" "^From:.*notifications@basecamp.com.*$")
             ("arch" "^To:.*arch-general@archlinux.org.*$")
             ("emacs devel" "^To:.*emacs-devel@gnu.org.*$")
             ("emacs devel" "^CC:.*emacs-devel@gnu.org.*$")
             ("bug-hurd" "^To:.*bug-hurd@gnu.org.*$")
             ("emacs bugs" "^CC:.*@debbugs.gnu.org.*$")
             ("bug-hurd" "^Cc:.*bug-hurd@gnu.org.*$")))

   #+END_SRC

   This just creates topics but doesn't seem to support splitting of groups

     (eval-after-load 'gnus-topic
       '(progn
          (setq gnus-message-archive-group '((format-time-string "sent.%Y")))
          (setq gnus-topic-topology '(("Gnus" visible)
                                      (("misc" visible))
                                      (("hotmail" visible nil nil))
                                      (("dismail" visible nil nil))))

          (setq gnus-topic-alist '(("Accrisoft Support")
                                   ("Basecamp")
                                   ("Arch")
                                   ("bug-hurd")
                                   ("hotmail" ; the key of topic
                                    "nnimap+hotmail:Inbox"
                                    "nnimap+hotmail:Drafts"
                                    "nnimap+hotmail:Sent")
                                   ("dismail" ; the key of topic
                                    "INBOX"
                                    "[Dismail]/Sent Mail"
                                    "Drafts")
                                   ("misc"  ; the key of topic
                                    "nnfolder+archive:sent.2015-12"
                                    "nnfolder+archive:sent.2016"
                                    "nndraft:drafts")
                                   ("Gnus")))))

*** COMMENT Encrypting Email

   Here follows a short rant:

   Most email that you send, gets sent to a MUA, or mail user agent, which then sends it to another MUA, which gets read by the
   recipent of your email.  HOWEVER, when one MUA sends an email to another MUA, that message is usually send in *plain text*.  So
   when you send an email ANYONE can read it. /ANYONE/.  To fix this, you have two options, you can encrypt your email yourself,
   or have some big server (that you don't own) do it for you.  I'm all for encrypting it myself.  If you are going to do this,
   I'd reccommend you read up on using gpg or Gnu Privacy Guard.  It is the best free/libre encrypting software.


 # default encryption and signing of stuff
 # https://www.gnu.org/software/emacs/manual/html_node/gnus/Security.html#Security
**** sign and encrypt messages
    [[info:gnus#Signing%20and%20encrypting][info:gnus#Signing and encrypting]]

    Let's go ahead and sign and encrypt messages if I recognize the senders by default
    #+BEGIN_SRC emacs-lisp
      (setq mm-verify-option 'known
       mm-decrypt-option 'known)
    #+END_SRC

**** On reply encrypt my email
    Let's reply and encrypt/sign messages if you know the user by default and if that message is encrypted
    https://www.gnu.org/software/emacs/manual/html_node/gnus/Security.html#Security
    #+BEGIN_SRC emacs-lisp
      (setq gnus-message-replysign t
       gnus-message-replyencrypt t)
    #+END_SRC
*** COMMENT Notification on new Mail
:PROPERTIES:
:ID:       c259ef9e-b4f2-4dd5-ba98-b36e645fab2f
:END:
   Have gnus alert you when a new mail arrives.
   #+BEGIN_SRC emacs-lisp :tangle no
     (use-package gnus-desktop-notify )
     (require 'gnus-desktop-notify)
   #+END_SRC

   This is supposed to let me know when I get a new email, but it's not working.
   http://www.thregr.org/~wavexx/software/gnus-desktop-notify.el/index.html

   #+BEGIN_SRC emacs-lisp
     (gnus-desktop-notify-mode)
     (gnus-demon-add-scanmail)
   #+END_SRC

   ;;alledigeely this next line is not necessary
   ;;(gnus-demon-init)
*** COMMENT gnus exit hook
#+BEGIN_SRC emacs-lisp :tangle no
  (add-hook 'kill-emacs-hook #'(lambda ()
                                 (interactive)
                                 (when (get-buffer "*Group*")
                                   (gnus-group-exit))))
#+END_SRC

*** COMMENT checking for new news
   :PROPERTIES:
   :ID:       15477e66-390a-4de9-955c-6290ce8937e5
   :END:
I got this code from John Wigley's .emacs

I'm not sure if this function will tell you if you have new news.
I'm also pretty sure that it won't flash an awesome popup window to tell you you have new news.
#+BEGIN_SRC emacs-lisp
  (defun gnus-demon-scan-news ()
    (interactive)
    (when gnus-plugged
      (let ((win (current-window-configuration))
            (gnus-read-active-file nil)
            (gnus-check-new-newsgroups nil)
            (gnus-verbose 2)
            (gnus-verbose-backends 5))
        (unwind-protect
            (save-window-excursion
              (when (gnus-alive-p)
                (with-current-buffer gnus-group-buffer
                  (gnus-group-get-new-news gnus-activate-level))))
          (set-window-configuration win)))))

  ;;
  ;;
  ;; (with-eval-after-load 'gnus
  ;;   (gnus-demon-add-handler 'gnus-demon-scan-news-2 5 2))
#+END_SRC

*** COMMENT Setting up Gnus to work with ebdb
   :PROPERTIES:
   :ID:       6be3f385-5122-4b63-9e38-78fa4e48cb19
   :END:

   The last time I used ebdb, it created an annoying popup everytime I
   completed someone's email contact information.  It is not helpful
   at all.
   #+BEGIN_SRC emacs-lisp
     (use-package ebdb )
     (require 'ebdb-gnus)
     (require 'ebdb-message)
   #+END_SRC

*** COMMENT Setting up Gnus to work with bbdb
   :PROPERTIES:
   :ID:       a6305580-2518-4fb1-ba39-b685694516f3
   :END:

   get bbdb set up (insidious big brother database) it manages your mail contacts http://bbdb.sourceforge.net/bbdb.html#SEC13 When you are about to email someone you can easily start typing their name then press tab to try to complete the email address

   Now you should be ready to go.  Say ‘M-x bbdb RET RET’ to open a bbdb buffer showing all entries.  Say ‘c’ to create a new
   entry, ‘b’ to search your BBDB and ‘C-o’ to add a new field to an entry.  If you want to add a sender to the BBDB you can also
   just hit ‘:’ on the posting in the summary buffer and you are done.  When you now compose a new mail, hit ‘TAB’ to cycle
   through know recipients.

   #+BEGIN_SRC emacs-lisp
     (use-package bbdb :defer t)
   #+END_SRC

    These are are needed to initial bbdb for gnus and message mode.

    http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-glimpse-of-bbdb.html

   Use bbdb when you read a message and when you send a message.  Though I should probably only store someone's email address
   when I send an email.
   #+BEGIN_SRC emacs-lisp
     (require 'bbdb)
     (bbdb-initialize 'gnus 'message)
   #+END_SRC

   Use bbdb in message mode.  This lets you begin to type out someone's name and then tab to complete their email address.

   #+BEGIN_SRC emacs-lisp
     (bbdb-insinuate-message)
   #+END_SRC

   Initialize bbdb for gnus.
   #+BEGIN_SRC emacs-lisp
     (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
   #+END_SRC

    [[info:gnus#FAQ%205-7][info:gnus#FAQ 5-7]]  how to use bbdb with gnus

   #+BEGIN_SRC emacs-lisp
   (setq bbdb/gnus-summary-prefer-real-names t
      bbdb-file "~/.config/emacs/bbdb"
      bbdb-default-area-code 765)
   #+END_SRC

   Don't set the variable bbdb/news-auto-create-p to t.  It creates bbdb records for all email that you read. BUT you might on
   occasion be fooded into reading junk mail.

   Make bbdb pop up when you are using it in gnus. It'll pop up when you are sending an email.  This is to let you know that
   gnus is saving a new record of that email address. Also make bbdb-save records without asking, because this is really nice.

   #+BEGIN_SRC emacs-lisp
     (setq
      bbdb-use-pop-up t
      bbdb-offer-save 1
      bbdb-update-records-p t)
   #+END_SRC

   I'm not sure what this does.

   #+BEGIN_SRC emacs-lisp
   (bbdb-mua-auto-update-init 'message)
   #+END_SRC

*** COMMENT Asynchronous Email

   This might not be worth it. Make gnus load more than 1 email in the background. This seems to slow stuff down in the initial
   connection, and it doesn't seem all that fast once everything is opened.


   (setq
   gnus-asynchronous t
   ;; fetch 15 messages by default
   gnus-use-article-prefetch 15)
* Some issues

I primarily use gnus for mailing lists, but mailing lists can be a little burdensome to use. There are several issues.  All which can be solved by specifying several rules. [fn:1]


** Your inbox gets flooded with emails from mailing lists

If you subscribe to several mailing lists then your inbox can easily
get several hundred new emails a day.  This is /not fun/.

The easiest way to filter mailing lists is to use the Header
"List-Id".  When you get an email from a mailing list, you'll have to
look at the email headers.  Gnus will help you do this.  FIXME change
M-x =gnu toggle headers= to the actual command that will show you the
header List-Id.  Then you can add an email filter.  If this header is
present, then store the email in a specific folder.

A decent work around is to subscribe to the mailing lists via the "+"
extension.  So instead of subscribing with email@dismail.de, one would
subscribe to the emacs mailing list via email+emacs-devel@dismail.de.
That gives you an easy way to filter email into appropriate folders.

Generally you want to use your mail server to filter emails.  In your
dismail.de account, you can specify mail filters to filter your email.

For example, if you subscribe to the guix-devel@gnu.org emailing list
with the email address "steven+guix-devel@gnu.org", in your dismail
folder you should specify a filter that looks for any To or CC that
/contains/ "guix-devel@gnu.org", and if it finds it, dismail.de will
move that email into a specified folder.

** People reply to you and the mailing list

The method described here may not work.  There is an option in the web
administration that says avoid getting duplicate messages, but they
may only work if you are subscribed to several email lists...

When you decide to reply to someone, they sometimes (always), send an email directly to you and they CC the mailing list.  This means you get two emails!  One in your inbox and one in your emacs-devel folder.

The easiest way to do this, is to log into the mailing list administration settings and specify that you do not want duplicate emails.  If you do not know how to do this, keep reading:

You could add a rule that deletes mails sent to your inbox with your normal email AND that CCs a mailing list.  This would look like:

if

email is sent to email@dismail.de

AND

email is CC to emacs-devel

delete the message.

Now when someone replies to you, you only see one email.
** Managing Spam
   :PROPERTIES:
   :ID:       c4f65821-d059-4f6d-ac7a-407e227e1bed
   :END:

Don't use gnus' spamming filters.  You want your mail server (aka
dismail.de), to deal with spam, NOT your email client.  Your email
client is generally super slow.  They server is better at filtering
spam.

** email you send to the mailing list is marked unread

When you reply to someone on the mailing list, the email is sent to you as well.  That email ends up in your emacs-devel folder.  So when you open your email the next time, you will see that you have one unread message in your emacs-devel folder.  When you open the folder, you will discover that you in fact sent that email, and you have already read it!

One way around this is to mark the message sent from you to emacs-devel as read.  You can do this by saying

if

email is send to emacs-devel@gnu.org

AND

email is sent from steven@dismail.de

mark email as read
* other good guides

https://github.com/gongzhitaao/GnusSolution

https://github.com/jwiegley/dot-emacs/blob/master/dot-gnus.el
* Footnotes

[fn:3] I know Gnus is dumb.  It should just show all of your email folders by default.

[fn:2] While connecting to your email with IMAP is the easiest way to do it, you might be disappointed with Gnus searching abilities, which generally are not that great or fast.  The /best/ Gnus set up (as of 2018), is to have a local maildir that is served via a local dovecot instance, that Gnus connects via a local IMAP connection...Obviously that is a lot to get set up properly.   The *other* alternative is to use Gnus with a maildir, which Gnus does support, but you would have to use set up a maildir search engine.  If you decide to do that, I would recommend that you set up the notmuch maildir engine.


[fn:1] These issues can probably be resolved via Sieve mail filtering language much easier. https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)
